<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>子传子</title>
    <script src="./js/vue2.js"></script>
</head>
<body>
    <div id="app">
        <father></father>
    </div>
    <template id="father">
        <div class="father">
            <p>我是父组件{{fname}}</p>
            <son></son>
            <daughter></daughter>
        </div>
    </template>
    <template id="son">
        <div class="son">
            <p>我是子组件1{{sname}}</p>
            <p>我妹妹今天跟我说她有男朋友了 ，名字叫做{{meifu}}</p>
            
        </div>
    </template>
    <template id="daughter">
        <div class="daughter">
            <p>我是子组件2{{dname}}</p>
            <input type="button" value="点击告诉你" @click="tellname">
        </div>
    </template>
</body>
<script>
    // 创建 一个事件总线的实例对象
    var bus = new Vue()

    Vue.component('father',{
        template:'#father ',
        data(){
            return {
                fname:'hansen'
            }
        },
        components: {
            'son':{
                template:'#son',
                data(){
                    return{
                        sname:'jack',
                        meifu:'??'
                    }
                },
                mounted () {
                    bus.$on('getname',(data)=>{
                        this.meifu=data;
                    })
                }
            },
            'daughter':{
                template:'#daughter',
                data(){
                    return {
                        dname:'ailis',
                        mybfname:'程咬金'
                    }
                },
                methods: {
                    tellname(){
                        bus.$emit('getname',this.mybfname)
                    }
                }
            }
        }
    })
    var vm = new Vue({
        el:'#app',
        data:{

        }
    })
</script>
</html>